package com.dkd.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dkd.dao.SkuClassDao;
import com.dkd.entity.SkuClassEntity;
import com.dkd.entity.SkuEntity;
import com.dkd.entity.dto.VmPageDto;
import com.dkd.entity.vo.SkuClassPageVo;
import com.dkd.entity.vo.SkuPageVo;
import com.dkd.service.SkuClassService;
import com.dkd.service.SkuService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class SkuClassServiceImpl extends ServiceImpl<SkuClassDao, SkuClassEntity> implements SkuClassService {
    private final SkuService skuService;
    @Override
    public boolean updateSkuClass(SkuClassEntity skuClassEntity) {
        return    this.updateById(skuClassEntity);
    }

    @Override
    public SkuClassPageVo searchSku(VmPageDto vmPageDto) {
        Integer pageIndex = vmPageDto.getPageIndex();
        Integer pageSize = vmPageDto.getPageSize();
        String skuClassName = vmPageDto.getName();
        Page<SkuClassEntity> page = new Page<>(pageIndex,pageSize);
        this.lambdaQuery().like(skuClassName!=null,SkuClassEntity::getClassName,skuClassName).page(page);
        long totalCount = page.getTotal();
        long totalSize = totalCount / pageSize;
        return new SkuClassPageVo(pageIndex.toString(),
                pageSize.toString(),
                String.valueOf(totalSize),
                String.valueOf(totalCount),
                page.getRecords());
    }
}
